//
//  viewtableViewHeaderView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2021/1/30.
//  Copyright © 2021 热带雨林. All rights reserved.
//

#import "viewtableViewHeaderView.h"
#import "GDListView.h"
#import "GDImageView.h"

@interface viewtableViewHeaderView()<GDListViewDelegate,GDImageViewDelegate>

@property (nonatomic, strong) UIView *imformationView;
@property (nonatomic, strong) UIView *buttonView;
@property (nonatomic, strong) UIStackView *stackView;
@property (nonatomic, strong) UIStackView *secoundStackView;
@property (nonatomic, strong) GDListView *listView;
@property (nonatomic, strong) GDImageView *imageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *descLabel;
@property (nonatomic, strong) UIButton *inforBtn;
@property (nonatomic, strong) UIStackView *firstStackView;
@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation viewtableViewHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{

    //----------------第一层--------------------
    self.imformationView = [[UIView alloc]initWithFrame:CGRectZero];
    self.imformationView.backgroundColor = NormalColor;
//    [self addSubview:self.imformationView];
    self.imformationView.layer.cornerRadius = 10.0f;
    self.imformationView.layer.masksToBounds = YES;
    //
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.text = @"Set a Google Analytics Code";
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.font = [UIFont fontWithName:Helvetica size:20];
    
    self.descLabel = [[UILabel alloc]init];
    self.descLabel.text = @"Blue sky is waiting for misty rain, while I'm waiting for you";
    self.descLabel.numberOfLines = 0;
    self.descLabel.textColor = [UIColor whiteColor];
    self.descLabel.font = [UIFont systemFontOfSize:13];
    
    self.inforBtn = [[UIButton alloc]initWithFrame:CGRectZero];
    [self.inforBtn setTitle:@"Login" forState:UIControlStateNormal];
    [self.inforBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.inforBtn.backgroundColor = [UIColor blackColor];
    self.inforBtn.layer.cornerRadius = 10.0f;
    self.inforBtn.layer.masksToBounds = YES;
    
    self.firstStackView = [[UIStackView alloc]initWithArrangedSubviews:@[self.nameLabel,self.descLabel,self.inforBtn]];
    [self.imformationView addSubview:self.firstStackView];
    self.firstStackView.spacing = 5.0f;
    self.firstStackView.axis = UILayoutConstraintAxisVertical;
    self.firstStackView.distribution = UIStackViewDistributionFillEqually;
    self.firstStackView.alignment = UIStackViewAlignmentFill;
    [self.firstStackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imformationView).offset(20);
        make.left.equalTo(self.imformationView).offset(20);
        make.width.mas_equalTo((GDScreenW - 60)/2 - 30);
        make.bottom.equalTo(self.imformationView.mas_bottom).offset(-10);
    }];
    
    self.imageV = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self.imformationView addSubview:self.imageV];
    self.imageV.image = [UIImage imageNamed:@"nihao"];
    //图片适中展示
    self.imageV.contentMode = UIViewContentModeScaleAspectFill;
    self.imageV.clipsToBounds = YES;
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imformationView).offset(0);
        make.left.equalTo(self.firstStackView.mas_right).offset(10);
        make.right.mas_equalTo(self.imformationView.mas_right).offset(-10);
        make.bottom.mas_equalTo(self.imformationView.mas_bottom).offset(0);
    }];
    
    //----------------第二层--------------------
    self.buttonView = [[UIView alloc]initWithFrame:CGRectZero];
    self.buttonView.backgroundColor = [UIColor clearColor];
    self.buttonView.layer.cornerRadius = 10.0f;
    self.buttonView.layer.masksToBounds = YES;
    
    //buttonView中的stackView
    self.listView = [[GDListView alloc]initWithFrame:CGRectZero];
    self.listView.layer.cornerRadius = 10.0f;
    self.listView.layer.masksToBounds = YES;
    self.listView.delgate = self;
    
    self.imageView = [[GDImageView alloc]initWithFrame:CGRectZero];
    self.imageView.delgate = self;
    self.imageView.layer.cornerRadius = 10.0f;
    self.imageView.layer.masksToBounds = YES;
    
    self.secoundStackView = [[UIStackView alloc]initWithArrangedSubviews:@[self.listView,self.imageView]];
    [self.buttonView addSubview:self.secoundStackView];
    self.secoundStackView.spacing = 20.0f;
    self.secoundStackView.axis = UILayoutConstraintAxisHorizontal;
    self.secoundStackView.distribution = UIStackViewDistributionFillEqually;
    self.secoundStackView.alignment = UIStackViewAlignmentFill;
    [self.secoundStackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.buttonView);
    }];

    
    //最外层的stackView
    self.stackView = [[UIStackView alloc]initWithArrangedSubviews:@[self.imformationView,self.buttonView]];
    self.stackView.spacing = 20;
    self.stackView.axis = UILayoutConstraintAxisVertical;
    self.stackView.distribution = UIStackViewDistributionFillEqually;
    self.stackView.alignment = UIStackViewAlignmentFill;
    [self addSubview:self.stackView];
    [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(GDScreenW - 30);
        make.height.mas_equalTo(GDScreenW - 20);
    }];
    //创建按钮
}
#pragma mark - GDListView的代理方法
- (void)callBackWithindexPath:(NSInteger)indexPath{
    if([self.delegate respondsToSelector:@selector(selectWithIndexPath:)]){
        [self.delegate selectWithIndexPath:indexPath];
    }
}
#pragma mark - GDImageView代理方法
- (void)showImageView{
    if([self.delegate respondsToSelector:@selector(showImaViewIfClick)]){
        [self.delegate showImaViewIfClick];
    }
}
@end
